<?php
	include "../public/commom/config.php";
	include "../public/commom/commom.php";
?>

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>商品</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
		<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
		<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
		<link rel="stylesheet" type="text/css" href="public/css/index.css"/>
		<script src="../public/js/ryan.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
		<?php include "public/commom/header.php"; ?>
		
		<div id="shop">
			<div class="shop-img">
				<ul>
					<?php
						if($_GET) {
							$shop_id = $_GET["shop_id"];
							
							$sql1 = "SELECT * FROM shop WHERE id = '$shop_id'";
							
							$result1 = mysqli_query($conn, $sql1);
							
							while($row = mysqli_fetch_assoc($result1)) {
								echo "<li><img src='" . $imgPath . $row["img"] . "'/></li>";
							}
							
							$sql2 = "SELECT * FROM shopimg WHERE shop_id = '$shop_id'";
							
							$result2 = mysqli_query($conn, $sql2);
							
							while($row = mysqli_fetch_assoc($result2)) {
								echo "<li><img src='" . $imgPath . $row["img"] . "'/></li>";
							}
						}
					?>
				</ul>
			</div>
			<div class="shop-content">
				<?php
					if($_GET) {
						$shopsql = "SELECT shop.*, area.name aname, store.name sname, store.logo FROM shop LEFT JOIN area ON (shop.area_id = area.id) LEFT JOIN store ON (shop.store_id = store.id) LEFT JOIN brand ON (shop.brand_id = brand.id) LEFT JOIN class ON (brand.class_id = class.id) WHERE shop.id = '$shop_id'";
						$shopresult = mysqli_query($conn, $shopsql);
						
						while($row = mysqli_fetch_assoc($shopresult)) {
							?>
							
								<p><span>￥</span><?php echo $row["price"]; ?></p>
								<h1><?php echo $row["name"]; ?></h1>
								<div class="txt">
									<span>销量<?php echo $row["sales"]; ?></span>
									<span>地区<?php echo $row["aname"]; ?></span>
								</div>
								<div class="shop-store">
									<div class="shop-info">
										<div class="logo">
											<img class="rounded-circle" src="<?php echo $imgPath . $row["logo"]; ?>"/>
										</div>
										<div class="content">
											<h1><?php echo $row["sname"]; ?></h1>
											<span><?php echo $row["aname"]; ?></span>
										</div>
									</div>
									<div class="abtn">
										<a href="javascript:;">联系店铺</a>
										<a href="store.php?store_id=<?php echo $row["store_id"]; ?>">进入店铺</a>
									</div>
								</div>
							<?php
						}
					}
				?>
			</div>
			<div class="shop-leaveword">
				<h1>留言区</h1>
				<form action="leaveword.php" method="post">
					<div style="margin-bottom: 0px;" class="form-group">
						<input type="text" class="form-control" name="content" autocomplete="off" />
					</div>
					<input type="hidden" name="shop_id" value="<?php echo $shop_id; ?>" />
					<input type="submit" class="btn-block" value="留言"/>
				</form>
				<div class="leaveword-content">
					<h2>用户留言</h2>
					<ul>
						<?php
							$sql = "SELECT leaveword.*, user.username uname FROM leaveword LEFT JOIN user ON (leaveword.user_id = user.id) WHERE leaveword.shop_id = '$shop_id'";
							
							$result = mysqli_query($conn, $sql);
							
							while($row = mysqli_fetch_assoc($result)) {
								echo "<li>
										<h1><a href='personal.php?user_id=" . $row["user_id"] . "'>" . $row["uname"] . "</a></h1>
										<p>" . $row["content"] . "</p>
										<p><span>" . date("Y-m-d H:i:s", $row["time"]) . "</span></p>
									</li>";
							}
							
							mysqli_close($conn);
							
						?>
					</ul>
				</div>
			</div>
		</div>
		
		
		
		<script type="text/javascript">
			window.onload = function () {
			/*可视区宽度*/
			var clientWidth = document.documentElement.clientWidth;
			
			/*商品变量*/
			var oShp = document.getElementById("shop");
			var oShpUl = oShp.getElementsByTagName("ul")[0];
			var aShpLi = oShpUl.getElementsByTagName("li");
			
			for (var i = 0; i < aShpLi.length; i++) {
				aShpLi[i].style.width = clientWidth + "px";
			}
			
			var shpIndex = 1;
			function shop() {
				if (aShpLi.length == 1) return;
				
				startMove(oShpUl, {left: shpIndex * -aShpLi[0].offsetWidth});
				
				if (shpIndex == aShpLi.length - 1) {
					shpIndex = -1;
				}
				
				shpIndex++;
			}
			
			setInterval(shop, 5000);
		}
		</script>
	</body>

</html>